#ifndef GOODINFODAO_H
#define GOODINFODAO_H

#include "iostream"
#include "vector"
#include "goodinfo.h"
#include "map"
#include "QVariantList"

namespace DAO {
class GoodInfoDao;
}

class QSqlDatabase;
class QSqlQuery;
class QString;


class GoodInfoDao
{
private:
    GoodInfoDao();
    ~GoodInfoDao();

private:
    static GoodInfoDao* instance;

public:
    static GoodInfoDao* GetInstance();

    bool Update(GoodInfo good_info);
    void Delete(GoodInfo good_info);
    void Insert(std::vector<GoodInfo> good_infos);
    void Insert(GoodInfo good_info);
    std::vector<GoodInfo> Select(QString search_id);
    std::vector<GoodInfo> ReadFullTableData();

private:
    void GoodInfoDao::BatchInsert(std::map<QString, QVariantList > good_info_map, QSqlQuery* query);
    void ExecQuery(QSqlQuery* query,QString meg);
    void CreateDirIfNotExist();

private:
    QSqlDatabase *m_db;
    QSqlQuery *m_db_query;
    const QString m_db_path;
    const QString m_db_table_name;
    const QString m_user_name;
    const QString m_user_pw;

private:
    void CreateTable();
    bool CheckTableIsExist();
    QSqlQuery *GetCleanQuery();
};


#endif // GOODINFODAO_H
